<template>
  <div class="index">
    <!-- 顶部 -->
    <div class="top"><Admin></Admin></div>
    <!-- bottom -->
    <div class="bottom">
      <div class="left"><SideNav></SideNav></div>
      <div class="right">
        <div class="content">
          <el-scrollbar style="height: 100%;">
            <!-- 当前位置 -->
            <div class="current_position">
              <p class="breadcrumb">当前位置 :</p>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item class="up">生活服务</el-breadcrumb-item>
                <el-breadcrumb-item>热词广告</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <!-- 搜索框热词 -->
            <div class="hot-title">搜索框热词</div>
            <div class="userlist">
              <div class="status_box">
                <div class="input">
                  <el-input v-model="word" placeholder="输入添加热词" clearable></el-input>
                </div>
                <div class="search"><el-button @click="addWord()">添加</el-button></div>
              </div>
              <div class="table">
                <el-table ref="multipleTable" :data="wordList" border tooltip-effect="dark" style="width: 100%">
                  <el-table-column prop="word" label="轮播热词"></el-table-column>
                  <el-table-column label="操作" fixed="right" width="200">
                    <template slot-scope="scope">
                      <el-button @click="delWord(scope.row)" type="text" size="small" class="hot-button">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  let moment = require("moment")
  import Admin from '@/components/Admin.vue'
  import SideNav from '@/components/SideNav.vue'
  export default {
    name: 'HotWord',
    components:{
      Admin,
      SideNav
    },
    data () {
      return {
        page: 1,//页码
        pageSize: 50,//每页条数
        wordList:[],//热词列表
        word:null,//热词
      }
    },
    mounted() {
      this.findWordList();
    },
    methods: {
      //添加热词
      addWord(){
        console.log("输入的热词是：",this.word)
        this.$axios.post(this.baseURL1+'admin/searchWord/add',{
          'word':this.word,
          "requestSource":"PC"
        }).then((res)=>{
          if(res.data.code==1){
            this.findWordList()
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      //查询热词列表
      findWordList(){
        this.$axios.post(this.baseURL1+'admin/searchWord/list',{
          "page":this.page,
          "size":this.pageSize,
          "requestSource":"PC"
        }).then((res)=>{
          if(res.data.code==1){
            this.wordList = res.data.data.records;
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      //删除某一个热词
      delWord(row){
        console.log("要删除的热词是：",row.id)
        this.$confirm('确认删除该热词?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post(this.baseURL1+'admin/searchWord/delete',{
            'id':row.id,
            "requestSource":"PC"
          }).then((res)=>{
            if(res.data.code==1){
              this.findWordList()
            }
          }).catch((err)=>{
            console.log('request fail', err);
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      }
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  @import '@/assets/css/index.scss'; //这个分号一定要写，要不会报错
  @import '@/assets/css/user.scss'; //这个分号一定要写，要不会报错
  .hot-title{
    width: 100%;
    height: 30px;
    background-color: #cfcfcf;
    padding: 0 20px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    line-height: 30px;
  }
  >>> .el-button{
    background-color:#409eff!important;
  }
  >>> .hot-button{
    background-color:transparent!important;
  }
  .table{
    margin: 0 10px;
  }
</style>
